package com.itheima.web.service.impl.oms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.result.PageResult;
import com.itheima.service.oms.OmsOrderReturnReasonService;
import com.itheima.vo.oms.OmsOrderReturnReason;
import com.itheima.web.mapper.oms.OmsOrderReturnReasonMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

@DubboService
public class OmsOrderReturnReasonServiceImpl extends ServiceImpl<OmsOrderReturnReasonMapper, OmsOrderReturnReason> implements OmsOrderReturnReasonService {

    @Autowired
    private OmsOrderReturnReasonService orderReturnReasonService;
    @Override
    public PageResult listPage(Integer pageNum, Integer pageSize) {
        Page<OmsOrderReturnReason> pageInfo = new Page<>();
        LambdaQueryWrapper<OmsOrderReturnReason> lqw = new LambdaQueryWrapper<>();
        lqw.orderByAsc(OmsOrderReturnReason::getSort);
        this.page(pageInfo,lqw);
        return PageResult.init(pageInfo.getTotal(), pageNum.longValue(), pageSize.longValue(), pageInfo.getRecords());
    }

    @Override
    public Boolean updateReturnReason(Long id, OmsOrderReturnReason reason) {
        reason.setId(id);
        reason.setCreateTime(LocalDateTime.now());
        return orderReturnReasonService.updateById(reason);
    }
}
